import { Graphics, Layers } from "cc";

export class AsteroidView extends Graphics {
    private _radius: number;
    public set radius(value: number) {
        this._radius = value;
    }
    
    protected start(): void {
        this.node.layer = Layers.Enum.UI_2D;
        this.fillColor.fromHEX('#ffffff');
        this.moveTo(this._radius, 0);
        let angle = 0;
        while (angle < Math.PI * 2) {
            const length: number = (0.75 + Math.random() * 0.25) * this._radius;
            const posX: number = Math.cos(angle) * length;
            const posY: number = Math.sin(angle) * length;
            this.lineTo(posX, posY);
            angle += Math.random() * 0.5;
        }
        this.lineTo(this._radius, 0);
        this.stroke();
        this.fill();
    }
}
